/**
* Abstract: Font (WebFont) loader helper
*
* Version: 1.0
*
* Disclaimer: IMPORTANT:  This Gamenova software is supplied to you by
* 4E Studios Srl("4E") in consideration of your agreement to the following terms,
* and your use, installation, modification or redistribution of this 4E software
* constitutes acceptance of these terms.  If you do not agree with these terms,
* please do not use, install, modify or redistribute this 4E software.
*
* In consideration of your agreement to abide by the following terms, and subject
* to these terms, 4E grants you a personal, non-exclusive license, under
* 4E's copyrights in this original 4E software (the "4E Software"), to
* use, reproduce, modify and redistribute the 4E Software, with or without
* modifications, in source and/or binary forms; provided that if you redistribute
* the 4E Software in its entirety and without modifications, you must retain
* this notice and the following text and disclaimers in all such redistributions
* of the 4E Software.
* Neither the name, trademarks, service marks or logos of 4E Studios Srl may be used
* to endorse or promote products derived from the 4E Software without specific
* prior written permission from 4E.  Except as expressly stated in this notice,
* no other rights or licenses, express or implied, are granted by 4E herein,
* including but not limited to any patent rights that may be infringed by your
* derivative works or by other works in which the 4E Software may be
* incorporated.
*
* The 4E Software is provided by 4E on an "AS IS" basis.  4E MAKES NO
* WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, REGARDING THE 4E SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
* COMBINATION WITH YOUR PRODUCTS.
*
* IN NO EVENT SHALL 4E BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
* DISTRIBUTION OF THE 4E SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
* CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
* 4E HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright (C) 2011 4E Studios Srl All Rights Reserved.
*/

/**
	Font loader helper class
	@constructor
*/
function GNFont()
{
	//mantain css references for exclude multiple loading of same font family
	this._fonts = {};

	/**
		Load a Font (WebFont) using a Font Configuration object (see @font-face format) :
		configObj = 
		{
			"font-family":"myFont",
			"font-style":"normal",
			"font-weight":"400",
			...
			"src":"url(./myfont.woff) format('woff')" 
		}
		supports @font-face formats (woff, tty, ...). tipically needs only 
		a "font-family" unique name and a "src" url and format specification.
	*/
	this.loadFont = function(fontConfig)
	{
		if(fontConfig)
		{
			var family = fontConfig["font-family"];
			if(family)
			{
				if(this._fonts[family]) return;
				else
				{
					var fontFaceArray = [];

					for(var i in fontConfig)
					{
						if(fontConfig[i]) fontFaceArray.push("" + i + " : " + fontConfig[i] + ";\n");
					}

					var fontFaceTxt = "@font-face{\n" + fontFaceArray.join(""); + "}\n";
					this._fonts[family] = fontFaceTxt;

					var cssNode = document.getElementById("GNFontCSS");
					if(cssNode)
					{
						cssNode.textContent += fontFaceTxt;
					}
					else
					{
						cssNode = document.createElement("style");
						cssNode.setAttribute("type","text/css");
						cssNode.textContent = fontFaceTxt;
						document.head.appendChild(cssNode)
					}					
				}
			}
		}
	}
}

window.GNFont = new GNFont();